package com.dlc.demo.daiqianma.activity;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
import android.widget.Toast;
import com.dlc.demo.daiqianma.R;
import com.dlc.demo.daiqianma.iview.IBaseView;

/**
 * Activity基类，所有Activity页面均基于此类
 */
public abstract class BaseActivity extends Activity implements IBaseView {
    private ProgressDialog mProgressDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //去掉标题栏
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        //限制仅允许竖屏
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        mProgressDialog = new ProgressDialog(this);
        mProgressDialog.setCancelable(false);
        mProgressDialog.setMessage("网络请求中，请稍等...");
    }

    @Override
    public void showLoading() {
        if (!mProgressDialog.isShowing()) {
            mProgressDialog.show();
        }
    }

    @Override
    public void hideLoading() {
        if (mProgressDialog.isShowing()) {
            mProgressDialog.dismiss();
        }
    }

    @Override
    public void showToast(String msg) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void showErr() {
        showToast(getResources().getString(R.string.api_error_msg));
    }

    @Override
    public Context getContext() {
        return BaseActivity.this;
    }

    /**
     * 顶部导航栏返回按钮事件
     * @param view
     */
    public  void _bank(View view){
        this.finish();
    }

    /**
     * 设置标题
     * @param title
     */
    public void setHeadTitle(String title){
        if (title==null || "".equals(title)) {
            return;
        }
        View v = findViewById(R.id.tv_head_title);
        if(v==null){
            return;
        }
        ((TextView)v).setText(title);
    }
}
